﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;

namespace BitcoinCommon.Data
{
    public class KorbitInfo
    {
        public string URL = "https://api.korbit.co.kr";
        public string ClientID = "RoEkfx7Zl6RCKwXCCmLAyXlMVVz1D9e9e1B4aMvD1eRHMSvOqownTzhaghCGf";
        public string ClientSecret = "mFgMCn8pTYrOZYJhABcqDoRNblyHQiTEYxI4kLX5ik4ZlS3Bo8BoNxv9SsdHk";
        public string UserID = "hyperioner@gmail.com";
        public string UserPWD = "overdrive@1";

        public string AccessToken = "";
        public string RefreshToken = "";

        int iNonce = 0;


        public KorbitInfo()
        {
            initializedNonce();
        }

        public void initializedNonce()
        {
            iNonce = (int)(DateTime.Now - DateTime.Parse("2015-03-01")).TotalSeconds;
        }

        public int Nonce()
        {
            return iNonce++;
        }

        public void SetLogin(string strData)
        {
            if (strData.Length == 0)
                return;

            JObject objData = JObject.Parse(strData);
            AccessToken = objData["access_token"].ToString();
            RefreshToken = objData["refresh_token"].ToString();
        }

        public Dictionary<string, string> GetURLParameterAccessKey()
        {
            if (AccessToken.Length == 0)
                return null;

            Dictionary<string, string> dicURLParameter = new Dictionary<string, string>();
            dicURLParameter.Add("access_token", AccessToken);
            dicURLParameter.Add("nonce", Nonce().ToString());

            return dicURLParameter;
        }
    }
}
